package com.qidian.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration //配置类
@EnableSwagger2// 开启Swagger2的自动配置
public class SwaggerConfig {
    @Bean
    public Docket docket(Environment environment) {

        //设置要显示的swagger环境
        Profiles profiles = Profiles.of("dev");
        //获取项目环境,
        boolean b = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("nlw")
                //是否启用
                .enable(b)
                .select()
                //RequestHandlerSelectors,配置要扫描接口的方式
                //any();扫描全部
                //none();不扫描
                //withClassAnnotation:扫描类上注解
                //withMethodAnnotation:扫描方法上的注解
                //.apis(RequestHandlerSelectors.basePackage("com.qidian.website.controller"))
                //path()过滤
//                .paths(PathSelectors.ant("/nlw/swagger/controller"))
                .build()
                ;
    }
    @Bean
    public Docket docketLiu(Environment environment) {

        //设置要显示的swagger环境
//        Profiles profiles = Profiles.of("dev");
        //获取项目环境,
//        boolean b = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfoLiu())
                .groupName("柳")
                //是否启用
//                .enable(b)
                .select()
                //RequestHandlerSelectors,配置要扫描接口的方式
                //any();扫描全部
                //none();不扫描
                //withClassAnnotation:扫描类上注解
                //withMethodAnnotation:扫描方法上的注解
                //.apis(RequestHandlerSelectors.basePackage("com.qidian.website.controller"))
                //path()过滤
//                .paths(PathSelectors.ant("/nlw/swagger/controller"))
                .build()
                ;
    }

    //配置Swagger信息
    private ApiInfo apiInfo() {
        //作者信息
        Contact contact = new Contact("nlw", "http://101.200.175.88:8080",
                "2991962721@qq.com");

        return new ApiInfo("未来日记", "未来的我,还是现在的我吗",
                "v1.0", "http://101.200.175.88:8080", contact,
                "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
    //配置Swagger信息
    private ApiInfo apiInfoLiu() {
        //作者信息
        Contact contact = new Contact("Liu", "http://101.200.175.88:8080",
                "627916289@qq.com");

        return new ApiInfo("未来日记", "未来可期",
                "v1.0", "http://101.200.175.88:8080", contact,
                "Apache 2.0", "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}